import logging
import traceback
from django.utils.deprecation import MiddlewareMixin

logger = logging.getLogger('django.request')


class ExceptionLoggingMiddleware(MiddlewareMixin):
    def process_exception(self, request, exception):
        logger.error(
            "未捕获异常\nPath: %s\n%s",
            request.path,
            traceback.format_exc(),
            extra={'request': request}
        )
        return None
